package com.iflytek.sbd.demo.lambda.mystream;

import com.iflytek.sbd.demo.lambda.Student;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @program: sbd
 * @description:
 * @author: 陈亮
 * @create: 2022-02-23 21:34
 */
public class StreamDemo {


    public static void main(String[] args) {

        ArrayList<Student> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            Student student = new Student();
            student.setName(i + "/" + i);
            student.setAge(i);
            list.add(student);
        }
        Student student = new Student();
        student.setName(2 + "/" + 2);
        student.setAge(999);
        list.add(student);
        System.out.println(list);
        Map<String, Integer> map = new HashMap<>();

        //list.forEach(student -> map.put(student.getName(),student.getAge()));

        Map<String, Integer> map1 = list.stream().collect(Collectors.toMap(Student::getName, Student::getAge, (a1, a2) -> a2));
        System.out.println(map1);

    }
}
